package com.whmall.service.crm.module.companyuser.impl;

import com.whmall.component.common.AbstractObjectValidator;
import com.whmall.service.crm.entity.dto.companyuser.CompanyUserRegisterReqDTO;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

@Component
public class CompanyUserValidator
        extends AbstractObjectValidator<CompanyUserRegisterReqDTO> {

    private static final Pattern REG_PASSWORD_COMBINATION = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$).{6,20}$");

    public void validatePassword(String newPassword, boolean isNullable) {
        validateExpression(newPassword, isNullable,
                () -> newPassword.length() >= 6 && newPassword.length() <= 20
                        && REG_PASSWORD_COMBINATION.matcher(newPassword).matches(),
                "密码必须含有字母数字组合且长度为6~20");
    }

    @Override
    public void validate(CompanyUserRegisterReqDTO target, boolean isNullable) {

    }
}
